package com.lv.common.dialog

import android.content.Context
import android.widget.TextView
import com.lv.common.R
import com.lv.common.base.BaseDialog
import com.lv.common.dialog.manager.ChainNode
import com.lv.common.dialog.manager.DialogChain
import com.lv.common.imp.OnDialogSureListener

/**
 * 作者： ygx
 * 创建日期：2022/5/18 9:53 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * _              _           _     _   ____  _             _ _
 * / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 */
class TipsDialog : BaseDialog ,ChainNode{
    private var title: String? = null
    private var content: String? = null
    private var tv_title: TextView? = null
    private var tvContent: TextView? = null
    private var tv_cancel: TextView? = null
    private var tv_sure: TextView? = null

    constructor(mContext: Context?, isCancelable: Boolean, isBackCancelable: Boolean) : super(
        mContext,
        isCancelable,
        isBackCancelable
    ) {
    }

    constructor(
        mContext: Context?,
        title: String?,
        content: String?,
        isCancelable: Boolean,
        isBackCancelable: Boolean,
        onDialogSureListener: OnDialogSureListener?
    ) : super(mContext, isCancelable, isBackCancelable) {
        this.title = title
        this.content = content
        this.onDialogSureListener = onDialogSureListener
    }

    constructor(
        mContext: Context?,
        isCancelable: Boolean,
        isBackCancelable: Boolean,
        gravity: Int,
        widthIsMatch: Boolean,
        heightIsMatch: Boolean
    ) : super(mContext, isCancelable, isBackCancelable, gravity, widthIsMatch, heightIsMatch) {
    }

    override fun initView() {
        tv_title = findViewById(R.id.tv_title)
        tvContent = findViewById(R.id.tv_content)
        tv_cancel = findViewById(R.id.tv_cancel)
        tv_sure = findViewById(R.id.tv_sure)
        initEvnet()
    }

    private fun initEvnet() {
        tv_title!!.text = title
        tvContent!!.text = content
        tv_sure!!.setOnClickListener {
            if (onDialogSureListener != null) {
                onDialogSureListener!!.onSureClick("")
            }
            dismiss()
        }
        tv_cancel!!.setOnClickListener { dismiss() }
    }

    override fun getLayoutId(): Int {
        return R.layout.dialog_tips
    }

    private var onDialogSureListener: OnDialogSureListener? = null
    fun setOnDialogSureListener(onDialogSureListener: OnDialogSureListener?) {
        this.onDialogSureListener = onDialogSureListener
    }

    override fun getId(): Int =0

    override fun proceed(chain: DialogChain?) {
        show()
        setOnDismissListener { dialog -> chain?.proceed() }
    }
}